<#include "common/common.html"/>
<meta charset="UTF-8">
<#include "common/kindeditor.html"/>
<meta charset="UTF-8">
	<table
		     class="easyui-datagrid"   
		     id="datagrid"  
	         title="项目管理"  
	         url="${base}/project/list?my=${my}"
	         toolbar="#searchtool,#toolbar" 
	         pagination="true"
	         rownumbers="true" 
	         fitColumns="true"
	         singleSelect="true"
	         data-options="fit:false,border:false,pageSize:20,pageList:[5,10,15,20]" >   
	    <thead>  
	        <tr>
	            <th field="id" width="5%" checkbox="true"></th>  
	            <th field="projectNo" width="6%">项目编号</th> 
	            <th field="projectName" width="10%">项目标题</th>
	            <th field="industryStr" width="5%">所属行业</th>  
	            <th field="province" width="5%">地区</th> 
	            <th field="phone" width="10%">发布人账号</th> 
	            <th field="pusherName" width="5%">发布人</th> 
	            <th field="total" width="5%">金额(万元)</th>
	            <th field="mode" formatter="formatMode" width="5%">项目类型</th>            
	            <th field="authStr" width="5%">认证状态</th> 	             
	            <th field="userName" width="5%">操作员</th> 
	            <th field="pushtimeStr" width="5%">发布时间</th> 
				<th field="projectStatusStr" width="5%" >项目状态</th> 
	            <th field="operate" width="18%" formatter="formatOper">操作</th>   	         
	        </tr>  
	    </thead>  
	</table>  
<div id="searchtool" style="padding:5px">  
      <span>所属行业:</span><input type="text" id="qryIndustryId" value="" sytle="width:200px" />&nbsp;&nbsp;  
      <span>所在地区:</span><input type="text" id="qryProvince" value="" sytle="width:200px" />&nbsp;&nbsp;  
      <span>项目状态:</span><input type="text" id="qryProjectStatus" value="" sytle="width:200px" />&nbsp;&nbsp; 
      <span>认证状态:</span><input type="text" id="qryAuth" value="" sytle="width:200px" />&nbsp;&nbsp;<br>  
      <span>起始时间:</span><input class="easyui-datebox" id="qryStartDate" value="" sytle="width:200px" />&nbsp;&nbsp;
      <span>截至时间:</span><input class="easyui-datebox" id="qryEndDate" value="" sytle="width:200px" />&nbsp;&nbsp; 
      <span>关键字&nbsp;&nbsp;&nbsp;:</span><input type="text" id="qryKeyword" value="" sytle="width:200px" data-options="prompt:'标题/发布人/编号'"/>&nbsp;&nbsp;
      <span>项目类型:</span><input type="text" id="qryMode" value="" sytle="width:200px" />&nbsp;&nbsp;
      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:queryData({industryId:$('#qryIndustryId').combobox('getValue'),provincePostcode:$('#qryProvince').combobox('getValue')
    	  ,projectStatus:$('#qryProjectStatus').combobox('getValue'),auth:$('#qryAuth').combobox('getValue'),qryStartDate:$('#qryStartDate').datebox('getValue'),qryEndDate:$('#qryEndDate').datebox('getValue')
    	  ,qryKeyWord:$('#qryKeyword').val(),mode:$('#qryMode').combobox('getValue')});">搜索</a>  
</div> 
<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="openProjectNewDlg('添加','project/doadd','project-dlg','project-fm');">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="openProjectEditDlg('修改','project/doupdate','project-dlg','project-fm');">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="singleDel('project/dodelete');">删除</a>
</div>
<div id="project-dlg" class="easyui-dialog"  style="padding:10px 20px;" data-options="iconCls:'icon-edit',closed:true,modal:true,resizable:true,modal:true,buttons:'#dlg-buttons'" >
        <form id="project-fm" method="post">
        	<!-- <input type="hidden" name="id" id="id"> -->
        	<input type="hidden" name="intentionId" id="intentionId">
        	<input type="hidden" name="pusher" id="pusher">
        	<input type="hidden" name="province" id="province">
        	<input type="hidden" name="pic" id="pic">
         	<div class="fitem">
               <label>项目编号:</label>
               <input name="projectNo" id="projectNo"  disabled="disabled">&nbsp;&nbsp;
               <label>项目标题:</label>
               <input name="projectName" id="projectName" required="true" ><span style="color:red;">*</span>
	        </div>	      
	        <div class="fitem">
               <label>项目类型:</label>
               <input name="mode" id="mode" required="true"><span style="color:red;">*</span>
               <label>金额(万元):</label>
               <input name="total" id="total" required="true" class="easyui-textbox" data-options="validType:['intOrFloat']"><span style="color:red;">*</span>
	        </div>
            <div class="fitem">
                <label>所属行业:</label>
                <input name="industryId" id="industryId" class="easyui-textbox"  required="true"><span style="color:red;">*</span>
                <label>所属省份:</label>
                <input name="provincePostcode" id="provincePostcode" class="easyui-textbox" required="true"><span style="color:red;">*</span>
            </div>
            <div class="fitem">
                <label>发布人:</label>
                <input id="pusherName" name="pusherName"  class="easyui-textbox" readonly="readonly">&nbsp;&nbsp;
                <label>发布人账号:</label>
                <input name="phone" id="phone" class="easyui-textbox" class="easyui-textbox"  required="true"><span style="color:red;">*</span>
            </div>
            <div class="fitem">
                <label>认证状态:</label>
                <input name="auth" id="auth" required="true" class="easyui-textbox" ><span style="color:red;">*</span>

                <label>关联意向:</label>
                <input id="intentionStr" name="intentionStr" onclick="selIntention();" readonly="readonly">
            </div>
            <div class="fitem">
                <label style="vertical-align:top;">项目简介:</label>
                <textarea  name="intro" id="intro"  rows="5" style="width: 364px" size=10></textarea>
            </div>
            <div class="fitem">
                <label style="vertical-align:top;">项目地址:</label>
                <textarea  name="address" id="address"  rows="5" style="width: 364px" size=10></textarea>
            </div>
            <div class="fitem">
                <label>项目坐标:</label>
                <input name="geocoor" id="geocoor" class="easyui-textbox">
                <a href="http://api.map.baidu.com/lbsapi/getpoint/" target="_blank">&nbsp;查找坐标</a>
            </div>
          <!--   <div class="fitem" style="vertical-align:top;">
                <label>项目发展与目标:</label>
                 <textarea  name="destionation" id="destionation" rows="5" style="width: 364px" size=10></textarea>
            </div> -->
            <div class="fitem">
                <label style="vertical-align:top;">项目模式:</label>
                 <textarea  name="proMode" id="proMode" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div>
            <div class="fitem">
                <label style="vertical-align:top;">项目优势:</label>
                 <textarea  name="advantage" id="advantage" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div>
          <!--   <div class="fitem">
                <label style="vertical-align:top;">融资计划:</label>
                <textarea  name="plan" id="plan" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div> -->
            <div class="fitem">
                <label style="vertical-align:top;">机构简介:</label>
                 <textarea  name="company" id="company" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div>
          <!--   <div class="fitem">
                <label style="vertical-align:top;">产品简介:</label>
                 <textarea  name="product" id="product" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div>
            <div class="fitem">
                <label style="vertical-align:top;">团队简介:</label>
                 <textarea  name="team" id="team" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div> -->
            <div class="fitem">
                <label style="vertical-align:top;">竞争分析:</label>
                 <textarea  name="completion" id="completion" class="textarea easyui-validatebox" rows="5" style="width: 364px" size=10></textarea>
            </div>
        </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" id="saveBtn" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="javascript:mySubmit('project-dlg','project-fm')" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#project-dlg').dialog('close')" style="width:90px">取消</a>
</div>
<div id="intentionDiv" class="easyui-window"  style="padding:10px 20px" closed="true" modal="true">
</div>
<div id="preView" class="easyui-window"  style="padding:10px 20px" closed="true" modal="true">
</div>




<script type="text/javascript">
function clearKindEditorValue(){
	KindEditor.html("#intro","");
	KindEditor.html("#address","");
	KindEditor.html("#proMode","");
	KindEditor.html("#advantage","");
	KindEditor.html("#company","");
	KindEditor.html("#completion","");
}
var introEditor=null;
var addressEditor =null;
var proModeEditor=null;
var advantageEditor=null;
var companyEditor=null;
var completionEditor=null;

function initKindEditor(){
	if(!introEditor){
		introEditor = editor("intro");
	}
	if(!addressEditor){
		addressEditor = editor("address");
	}

	if(!proModeEditor){
		proModeEditor =editor("proMode");
	}
	if(!advantageEditor){
		advantageEditor = editor("advantage");
	}
	if(!companyEditor){
		companyEditor = editor("company");
	}
	
	if(!completionEditor){
		completionEditor = editor("completion");
	}
	
	prettyPrint();
}

$(function () {
	 $('#mode').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=300',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName'  
      });  
	 
	 $('#industryId').combobox({   
         url:base+'/industry/queryAllForProject',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'id',     
         textField:'industryName'  
      });  
	 
	 $('#provincePostcode').combobox({   
         url:base+'/cityinfo/findAllProvince',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'postcode',     
         textField:'cityName',
         onSelect:function(record){
             $('#province').val(record.cityName);
         }
      });  
	 
	 $('#auth').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=500',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName' 
      });  
	 
	 /////查询条件
	 $('#qryIndustryId').combobox({   
         url:base+'/industry/queryAllForProject',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'id',     
         textField:'industryName',
         loadFilter:function(data){
			    data.unshift({id:'-1',industryName:'所有'});
			    return data;
		      }
      });  
	 
	 $('#qryProvince').combobox({   
         url:base+'/cityinfo/findAllProvince',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'postcode',     
         textField:'cityName',
         loadFilter:function(data){
			    data.unshift({postcode:'-1',cityName:'所有'});
			    return data;
		      }
      });
	 
	 $('#qryProjectStatus').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=200',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName' ,
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
	 
	 $('#qryAuth').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=500',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName' ,
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
	 
	 $('#qryMode').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=300',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName' ,
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
});


function openProjectNewDlg(title,actUrl,dlgId,fmId){
	unmakeReadonly();
	clearKindEditorValue();
	initKindEditor();	
	centerDialog(dlgId).dialog('open').dialog('setTitle',title);
	if(fmId){
		$("#"+fmId).form('clear');
	}	
    url= $("#base").val()+"/"+actUrl;
}
function makeReadonly(){
	//项目标题、认证状态， 项目类型、金额、所属行业、 所属省份
	console.log("Make Readonly...");
	 $('#projectName').textbox({    
		 disabled:true
	 });
	 
	 $('#auth').textbox({    
		 disabled:true
	 });
	 $('#mode').combobox("disable");
	 $('#industryId').combobox("disable");
	 $('#provincePostcode').combobox("disable");
	 $('#total').textbox({    
		 disabled:true
	 });
}

function unmakeReadonly(){
	console.log("Unmake Readonly...");
	 $('#projectName').textbox({    
		 disabled:false
	 });
	 
	 $('#auth').textbox({    
		 disabled:false
	 });
	 
	 $('#mode').combobox("enable");
	 $('#industryId').combobox("enable");
	 $('#provincePostcode').combobox("enable");
	 
	 $('#total').textbox({    
		 disabled:false
	 });
	 

}
function formatOper(val,row,index){
	var viewPhotoUrl =base+"/project/viewPhoto?id="+row.id;
	var managePhotoUrl =base+"/project/managePhoto?id="+row.id;
	var marryFundUrl = base+"/project/managePhoto?id="+row.id;

	var viewPhoto = parent.buildTabUrl("图集",viewPhotoUrl,"图集");
	var managePhoto=parent.buildTabUrl("图集管理",managePhotoUrl,"图集管理");
	var marryFund = "<a href='javascript:showMarryFund1(\""+row.id+"\");'>匹配</a>";
	var showUser = "<a href='javascript:showUser(\""+row.id+"\");'>收藏人</a>";
   //发布状态下，隐藏图片管理
	if(row.projectStatus==203){
		managePhoto="";
	}
	return "<a href='javascript:showPreView("+row.id+")'>预览</a>|"+viewPhoto+"|"+managePhoto+"|"+marryFund+"|"+showUser;
}

function formatMode(val,row,index){
	if(val==301){
		return '股权';
	}
	else if(val==302){
		return '债权';
	}
	else if(val==303){
		return '资产交易';
	}
	else if(val==304){
		return '政府投资';
	}
	else {
		return '未知';
	}
}

var $winst;
function showMarryFund1(id){
   var windowWidth =$(window.parent).width();
   var windowHeight=$(window.parent).height();
   var width= windowWidth-200;
   var height=windowHeight-200;
   var top=(windowHeight-height)/2;
   var left=(windowWidth-width)/2;
    $winst = $('#intentionDiv').window({
    	href: base+'/project/showMarryFund?id='+id+'&noCache=random',
        title: '匹配管理',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });
    $('#datagrid').datagrid('clearSelections');
    $winst.window('open');
}

var $wins;
function showUser(id){
   var windowWidth =$(window.parent).width();
   var windowHeight=$(window.parent).height();
   var width= windowWidth-100;
   var height=windowHeight-200;
   var top=(windowHeight-height)/2;
   var left=(windowWidth-width)/2;
    $wins = $('#intentionDiv').window({
    	href: base+'/userStatistic/showUser?id='+id+'&noCache=random',
        title: '显示关注人',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });
    $('#datagrid').datagrid('clearSelections');
    $wins.window('open');
}


function showPreView(id){
    var href= '${mobileDomain}/projectApi/getProjectDetailPreView?id='+id;
    var windowWidth =$(window.parent).width();
    var windowHeight=$(window.parent).height();
    var width=380;
    var height=windowHeight-200;
    var top=(windowHeight-height)/2;
    var left=(windowWidth-width)/2;
    var $win2 = $('#preView').window({
   	   content : '<iframe scrolling="yes" frameborder="0"  src="'  
              + href  
              + '" style="width:100%;height:98%;"></iframe>',  
        title: 'APP预览',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });

    $win2.window('open');
}

function selIntention(){
   var rect=centerRect(window);
    var win = $('#intentionDiv').window({
    	href: base+'/project/selIntention',
        title: '选择意向',
        width: rect.width,
        height: rect.height,
        top: rect.top,
        left: rect.left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });

    win.window('open');
}

function doSelIntention(){
	var rows = $('#datagrid2').datagrid('getSelections');
    if (rows&&rows.length==1){
    	$('#intentionId').val(rows[0].id);
    	$('#pusher').val(rows[0].userId);
    	$("#pusherName").textbox('setValue',rows[0].userName);
    	$("#phone").textbox('setValue',rows[0].phone);
    	$("#intentionStr").val(rows[0].intro);
    	
    	$win.window('close');
    }else{
    	$.messager.alert('提示','请选择一条数据进行操作','info');
    }
}

function openProjectEditDlg(title,actUrl,dlgId,fmId){
	console.log("openProjectEditDlg");
 	unmakeReadonly();
	//增加的时候，可能去掉了disabled属性
	$("#projectNo").attr("disabled",true);
    var rows = $('#datagrid').datagrid('getSelections');
    if (rows&&rows.length==1){
    	centerDialog(dlgId).dialog('open').dialog('setTitle',title);
    	$("#"+fmId).form('clear');
    	$("#"+fmId).form('load',rows[0]);
        url = $("#base").val()+"/"+actUrl;
        if(rows[0].id){
        	url+='?id='+rows[0].id;
        }else if(rows[0].acl){
        	url+='?acl='+rows[0].acl;
        }else{
        	url+='?uid='+rows[0].uid;
        }
        var projectStatus =rows[0].projectStatus;
        //已发布状态下，部分字段不能修改
        if(projectStatus==203){
        	makeReadonly();
        }
        console.log(rows[0]);
        //编辑的时候，需要手动赋值
        KindEditor.html("#intro",rows[0].intro);
        KindEditor.html("#address",rows[0].address);
        KindEditor.html("#advantage",rows[0].advantage);
        KindEditor.html("#completion",rows[0].completion);
        KindEditor.html("#company",rows[0].company);
        KindEditor.html("#proMode",rows[0].proMode);
    }else{
    	$.messager.alert('提示','请选择一条数据进行操作','info');
    }
    initKindEditor();
}

function mySubmit(divId,formId){
	console.log("Try to submit project");
	var errFlag = true;
 	var rows = $('#datagrid').datagrid('getSelections');
	var selProjectId;
	if(rows&&rows.length==1){
		selProjectId = rows[0].id;
	}else{
		selProjectId = 0;
	}
	
	$.ajax({    
	    url:base+'/project/checkPhone',
	    data:{    
	    	phone : $("#phone").val()
	    },    
	    type:'post',    
	    cache:false, 
	    async: false,
	    dataType:'json',    
	    success:function(result) {
	    	if (result.msg) {
				$.messager.alert('错误', result.msg, 'error');
				errFlag = false;
			}
	    },    
	     error : function() {    
	         //alert("异常！");    
	    }    
	}); 
	if(null != $("#intentionId").val() && "" != $("#intentionId").val()){
		$.ajax({    
		    url:base+'/project/checkIntention',
		    data:{    
		    	intentionId : $("#intentionId").val(),
		    	projectId : selProjectId
		    },    
		    type:'post',    
		    cache:false, 
		    async: false,
		    dataType:'json',    
		    success:function(result) {
		    	if (result.msg) {
					$.messager.alert('错误', result.msg, 'error');
					errFlag = false;
				}
		    },    
		     error : function() {    
		         //alert("异常！");    
		    }    
		}); 
	}
	if(errFlag){
		//提交之前手动把KindEditor的值赋给表单
		$("#intro").val(introEditor.html());
		$("#address").val(addressEditor.html());
		$("#proMode").val(proModeEditor.html());
		$("#advantage").val(advantageEditor.html());
		$("#company").val(companyEditor.html());
		$("#completion").val(completionEditor.html());
				
		submit(divId,formId);
	}
	
}
</script>
 
